package cloud.maque.admin.impl;

import cloud.maque.admin.domain.entity.MqUserExtDef;
import cloud.maque.admin.mapper.MqUserExtDefMapper;
import cloud.maque.admin.service.MqUserExtDefService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author 4color
 * @description 用户扩展字段定义
 * @date 2023-03-17
 */
@Service
public class MqUserExtDefServiceImpl extends ServiceImpl<MqUserExtDefMapper, MqUserExtDef> implements MqUserExtDefService {

    @Override
    public MqUserExtDef insert(MqUserExtDef extDef) {
        Assert.hasText(extDef.getFieldName(), "字段不能为空");
        save(extDef);
        return extDef;
    }

    @Override
    public List<MqUserExtDef> list(MqUserExtDef ext) {
        QueryWrapper<MqUserExtDef> wrapper = new QueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(ext.getTenantId())) {
            wrapper.lambda().eq(MqUserExtDef::getTenantId, ext.getTenantId());
        }
        wrapper.lambda().orderByAsc(MqUserExtDef::getCreateAt);
        List<MqUserExtDef> lists = this.baseMapper.selectList(wrapper);
        return lists;
    }
}
